package NiuKe;

import java.util.HashSet;

public class IntegerCount {
    public static void main(String[] args) {

    }

    public int solve(String s) {
        HashSet<String> opsMap = new HashSet<>();
        opsMap.add("(");
        opsMap.add(")");
        opsMap.add("+");
        opsMap.add("-");
        opsMap.add("*");
        String[] counts = s.split("");
        String[] stackNum = new String[counts.length];
        String[] stackOps = new String[counts.length];
        int topNum = -1;
        int topOps = -1;
        for (int i = 0; i < counts.length; i++) {
            if (opsMap.contains(counts[i])) {
                stackOps[++topOps] = counts[i];
                if (stackOps[topOps].equals(")")) {
                    int result = count(stackOps[topOps - 1], counts[topOps - 3], counts[topOps - 1]);
                    topOps -= 4;
                    stackOps[topOps] = String.valueOf(result);
                }
            } else {
                stackNum[++topNum] = counts[i];
            }
        }
        return 0;
    }

    public int count(String c, String a, String b) {
        int m = Integer.parseInt(a);
        int n = Integer.parseInt(b);
        if (c.equals("+")) {
            return m + n;
        } else if (c.equals("-")) {
            return m - n;
        } else {
            return m * n;
        }
    }
}
